package reci.journal.utils;

import javax.swing.JOptionPane;

/*
 * Copyright (C) 2014 ReciGames
 * See notice in reci.journal.Main.java.
 */

/**general utilities*/
public class Util
{
//Strings
	
	/**
	 * @param n
	 * @param len
	 * @return 'n' prepended with 0s to be at least 'len' long
	 */
	public static String formatInt(int n, int len)
	{
		String s=""+n;
		
		while(s.length()<len)
		{
			s=0+s;
		}
		
		return s;
	}
	
	/**
	 * @param s
	 * @return 's' with '.' after each character
	 */
	public static String insertDots(String s)
	{
		StringBuffer sb=new StringBuffer();
		
		char[] cs=s.toCharArray();
		
		for(char c : cs)
		{
			sb.append(c);
			sb.append(".");
		}
		
		return sb.toString();
	}
	
//messages
	/**
	 * Alerts user.
	 * 
	 * @param message
	 */
	public static void alert(String message)
	{
		JOptionPane.showMessageDialog(null,message,"Alert",JOptionPane.ERROR_MESSAGE);
	}
	
	/**
	 * Alerts user of exception.
	 * 
	 * @param message
	 * @param e
	 */
	public static void alert(String message, Exception e)
	{
		alert(message+"\nError: "+e.getMessage());
	}
	
	/**
	 * Informs user.
	 * 
	 * @param message
	 */
	public static void info(String message)
	{
		JOptionPane.showMessageDialog(null,message,"Info",JOptionPane.INFORMATION_MESSAGE);
	}
}
